package com.gb.config;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * session监听
 *
 * @author liaosh
 * @version 1.0.0
 * @Date 2017/8/15 12:01
 */
public class MySessionListener implements SessionListener{

    protected Logger log = LoggerFactory.getLogger(MySessionListener.class);

    private final AtomicInteger sessionCount = new AtomicInteger(0);

    @Override
    public void onStart(Session session) {
        sessionCount.incrementAndGet();
        log.info("登录+1=="+sessionCount.get());
    }

    @Override
    public void onStop(Session session) {
        sessionCount.decrementAndGet();
        log.info("登录退出-1=="+sessionCount.get());
    }

    @Override
    public void onExpiration(Session session) {
        sessionCount.decrementAndGet();
        log.info("登录过期-1=="+sessionCount.get());
    }

    public int getSessionCount(){
        return sessionCount.get();
    }
}
